#include <windows.h>
#include <stdio.h>
#include <string.h>
#define LEN 1024
int mainRoutine(char *fullpath) ;
int IsEndWithH(char *fullPath)
{
	int i = 0;
	while(fullPath[i] != '\0')
	{
		i++;
	}
	if(i >= 2 &&
		((fullPath[i - 1] == 'h') || (fullPath[i - 1] == 'H'))
		&&(fullPath[i - 2] == '.')) 
	{
		return 0;
	}

	return 1;
}

BOOL  DirectoryList(char* Path)
{
	WIN32_FIND_DATAA FindData;
	HANDLE hError;
	int FileCount = 0;
	char FilePathName[LEN];
	// make path
	char FullPathName[LEN];
	strcpy(FilePathName, Path);
	strcat(FilePathName, "\\*.*");
	hError = FindFirstFileA(FilePathName, &FindData);
	if (hError == INVALID_HANDLE_VALUE)
	{
		printf("search fail!");
		return 0;
	}
	while (::FindNextFileA(hError, &FindData))
	{

		if (strcmp(FindData.cFileName, ".") == 0 
			|| strcmp(FindData.cFileName, "..") == 0 )
		{
			continue;
		}


		wsprintfA(FullPathName, "%s\\%s", Path,FindData.cFileName);
		FileCount++;

		if(IsEndWithH(FullPathName) == 0) 
			mainRoutine(FullPathName);
			//printf("\n%d  %s ", FileCount, FullPathName);

		if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
		{
			printf("<Dir>");
			DirectoryList(FullPathName);
		}
	}
	return 0;
}

